Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add transition router feature #11364

Closed
wants to merge 1 commit into from

Conversation

fz6m
Copy link
Member

@fz6m fz6m commented Jul 4, 2023

根据 remix-run/remix#5763React Docs Suspense 中的经验,我们把路由切换包裹在 startTransition 中,标记为非紧急更新,这可以避免 Suspense 的 fallback 闪烁问题,提升体验。

同时这应该可以解 antd 文档过早切换路由,水合失败的问题,详见:antd docs link 代码

cc @PeachScript

@vercel
Copy link

vercel bot commented Jul 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
umi ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 4, 2023 5:09pm

@codecov
Copy link

codecov bot commented Jul 4, 2023

Codecov Report

Patch coverage has no change and project coverage change: -0.04 ⚠️

Comparison is base (f3668f5) 29.03% compared to head (d34c1bc) 29.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #11364      +/-   ##
==========================================
- Coverage   29.03%   29.00%   -0.04%     
==========================================
  Files         484      485       +1     
  Lines       14667    14684      +17     
  Branches     3460     3463       +3     
==========================================
  Hits         4259     4259              
- Misses       9657     9672      +15     
- Partials      751      753       +2     
Impacted Files Coverage Δ
.../src/features/transitionRouter/transitionRouter.ts 0.00% <0.00%> (ø)
packages/preset-umi/src/index.ts 0.00% <ø> (ø)

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

const originPush = h.push
const originReplace = h.replace
h.push = (...args) => {
startTransition(() => originPush.apply(h, args))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

试了下会影响约定式 loading 的功能,在 startTransition 中切换路由时,Suspensefallback 组件就不会渲染了,不知道有没有其他解法

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是的,因为 startTransition 标记这个不是紧急的渲染,这样 fallback 就不会立即出现切换 UI ,这个是符合 startTransition 预期的,由于 Suspensefallback 其实很短,会一闪而过,体验不好,所以为了提升体验,现在更推荐使用非紧急的更新切换路由,包括 nextjs 等也是一样,切换的时候会阻塞,不会闪屏 loading 。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他框架的页面 loading 方案是怎么处理的呢,开启这个 Umi 的 loading 就失效了,希望能在解决注水错误的同时让 loading 继续生效

@fz6m fz6m closed this Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants